home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / vc / pro3 / shel2dos.c < prev    next >
C/C++ Source or Header  |  1993-05-25  |  2KB  |  79 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville MI
  3. Date: 05-23-93 (19:40)             Number: 65
  4. From: BOB STOUT                    Refer#: 176
  5.   To: DANIEL LYNES                  Recvd: NO  
  6. Subj: Shelling to OS                 Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. In a message of <May 22 00:58>, Daniel Lynes (1:229/516@fidonet) writes:
  9.  
  10.  >/* Demonstrates use of the system() function */
  11.  
  12.  >#include <stdlib.h>
  13.  
  14.  >main() {
  15.  >       char input[40];
  16.  >       input = "command.com"; /* Or 4DOS.COM, if you're using 4DOS */
  17.  >       system(input);   /* This is the line right here */
  18.  >}
  19.  
  20.   A more robust solution from SNIPPETS:
  21.  
  22. /*
  23. **  SHEL2DOS.C - Shell to DOS from a running program
  24. **
  25. **  Original Copyright 1989-1991 by Bob Stout as part of
  26. **  the MicroFirm Function Library (MFL)
  27. **
  28. **  This subset version is hereby donated to the public domain.
  29. */
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <process.h>
  35.  
  36. int shell_to_DOS(void)
  37. {
  38.       char *comspec, prompt[256], *oldprompt;
  39.       int retval;
  40.  
  41.       comspec = getenv("COMSPEC");
  42.       if(comspec == NULL)
  43.             comspec = "COMMAND.COM";     /* Better than nothing... */
  44.  
  45.       sprintf(prompt, "PROMPT=[Type EXIT to return to program]\r\n%s",
  46.             oldprompt = getenv("PROMPT"));
  47.       putenv(prompt);
  48.  
  49.       retval = spawnlp(0, comspec, comspec, NULL);
  50.  
  51.       sprintf(prompt, "PROMPT=%s", oldprompt);
  52.       putenv(prompt);
  53.  
  54.       return retval;
  55. }
  56.  
  57. #ifdef TEST
  58.  
  59. #include <stdio.h>
  60.  
  61. void main(void)
  62. {
  63.       int retval = shell_to_DOS();
  64.  
  65.       printf("shell_to_DOS() returned %d\n", retval);
  66.  
  67.       retval = shell_to_DOS();
  68.       printf("shell_to_DOS() returned %d\n", retval);
  69. }
  70.  
  71. #endif
  72.  
  73.  
  74. --- QM v1.00
  75.  * Origin: MicroFirm : Down to the C in chips (1:106/2000.6)
  76. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  77. SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 261/1023
  78. SEEN-BY: 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
  79.